import cae_model
import pred_model
import vehicle_analysis_py as measure_main
import bean.param as param
import time
import pandas as pd

import url_util



def testCaeType1():
    data = param.CaeData()
    data.spans = "[30,30]"
    data.width = "30"
    data.beam_type = "1"
    data.column_num="[1,1,1]"
    data.column_h="30"
    data.bridge_year = "2008"
    timeStart = time.time()

    req=param.AnalysisReq()
    req.bridgeType=1
    req.bridgeCode="3001"
    req.bridgeName="桥梁3001"
    pic_info_list, result = cae_model.analysis(req, data)
    print("testCaeType1 耗时：{}".format(time.time()-timeStart))
    print("testCaeType1 result：{}".format(result))
    print("testCaeType1 pic_info_list：{}".format(pic_info_list))


def testCaeType3():
    data = param.CaeData()
    data.spans = "[205,420,205]"
    data.width = "25"

    data.cable_plane_num="2"
    data.cable_num="25"

    data.tower_horizontal_type="1"
    data.tower_vertical_type="1"

    data.tower_h_ratio="3"
    data.tower_h_1="110.5"

    data.auxi_col_num="1"

    data.girder_mat="2"
    data.girder_type="5"

    data.bridge_year = "2008"
    timeStart = time.time()

    req = param.AnalysisReq()
    req.bridgeType = 3
    req.bridgeCode = "4001"
    req.bridgeName = "桥梁4001"
    result = cae_model.analysis(req, data)
    print("testCaeType3 耗时：{}".format(time.time() - timeStart))
    print("testCaeType3 result：{}".format(result))

def testPredType1():
    data = param.PreEvaluateData()
    data.mainSpan = "50"
    data.girderType = "1"

    timeStart = time.time()

    req=param.AnalysisReq()
    req.bridgeType=1
    req.bridgeCode="3001"
    req.bridgeName="桥梁3001"
    result = pred_model.analysis(req, data)
    print("testPredType1 耗时：{}".format(time.time()-timeStart))
    print("testPredType1 result：{}".format(result))


def testPredType3():
    data = param.PreEvaluateData()
    data.mainSpan = "420"
    data.mainBeamType = "混凝土梁"
    data.towerNumber = "2"
    data.towerHeight = "120"

    timeStart = time.time()

    req = param.AnalysisReq()
    req.bridgeType = 3
    req.bridgeCode = "3001"
    req.bridgeName = "桥梁3001"
    result = pred_model.analysis(req, data)
    print("testPredType3 耗时：{}".format(time.time() - timeStart))
    print("testPredType3 result：{}".format(result))

def testMesureType3():
    data = param.MeasureAnalysisData()
    data.sample_frequency="100"
    data.sample_type="1"
    data.sample_urls=[
        "https://example.com/data1.csv"
    ]
    data.epsg="32610"

    timeStart = time.time()

    bridge_type = 3

    NN_df = pd.DataFrame({
        '振型阶数': [1, 2, 3],
        '固有频率(Hz)': [0.26, 0.33, 0.6],
        '振型阻尼比': [0.01, 0.02, 0.03]
    })

    CAE_df = pd.DataFrame({
        '振型阶数': [1, 2, 3],
        '固有频率(Hz)': [0.26, 0.33, 0.6],
        '振型阻尼比': [0.01, 0.02, 0.03],
        '模态质量(t)': [100, 200, 300]
    })

    url_list =["https://haoyaguanjia.oss-cn-hangzhou.aliyuncs.com/bridge/dev/files/csv/1001/1001_sample_02.csv",
               "https://haoyaguanjia.oss-cn-hangzhou.aliyuncs.com/bridge/dev/files/csv/1001/1001_sample_01.csv"]

    param_dict = {
        '采样频率': 100,
        '桥梁全长': 420,
        '桥梁EPSG代号': 32651,
    }
    print("开始")
    result =  measure_main.vehicle_analysis_module(param_dict,url_list,NN_df,CAE_df,bridge_type)
    print("结束:{}".format(result))


def testMesureType3_2():
    bridge_type = 3

    NN_df = pd.DataFrame({
        '振型阶数': [1, 2, 3],
        '固有频率(Hz)': [0.26, 0.33, 0.6],
        '振型阻尼比': [0.01, 0.02, 0.03]
    })

    CAE_df = pd.DataFrame({
        '振型阶数': [1, 2, 3],
        '固有频率(Hz)': [0.26, 0.33, 0.6],
        '振型阻尼比': [0.01, 0.02, 0.03],
        '模态质量(t)': [100, 200, 300]
    })

    # url_list = [
    #     "https://haoyaguanjia.oss-cn-hangzhou.aliyuncs.com/bridge/dev/files/csv/1001/1001_sample_02.csv",
    #     "https://haoyaguanjia.oss-cn-hangzhou.aliyuncs.com/bridge/dev/files/csv/1001/1001_sample_01.csv"
    # ]

    url_list = [
        "https://haoyaguanjia.oss-cn-hangzhou.aliyuncs.com/bridge/dev/files/csv/shipao/shipao_sample_1.csv",
        "https://haoyaguanjia.oss-cn-hangzhou.aliyuncs.com/bridge/dev/files/csv/shipao/shipao_sample_2.csv"
    ]

    param_dict = {
        '采样频率': 100,
        '桥梁全长': 100,
        '桥梁EPSG代号': 32651,
    }

    # 最终结果
    res = measure_main.vehicle_analysis_module(param_dict, url_list, NN_df, CAE_df, bridge_type)
    print(res)


def testMesureType3_1():
    bridge_type = 3

    NN_df = pd.DataFrame({
        '振型阶数': [1, 2, 3],
        '固有频率(Hz)': [0.26, 0.33, 0.6],
        '振型阻尼比': [0.01, 0.02, 0.03]
    })

    CAE_df = pd.DataFrame({
        '振型阶数': [1, 2, 3],
        '固有频率(Hz)': [0.26, 0.33, 0.6],
        '振型阻尼比': [0.01, 0.02, 0.03],
        '模态质量(t)': [100, 200, 300]
    })

    url_list = [
        "http://202.120.188.183:9093/api/uploads/files/csv/bridge_E121_541533_N31_257093/bridge_E121_541533_N31_257093_park_sample_1.csv",
        "http://202.120.188.183:9093/api/uploads/files/csv/bridge_E121_541533_N31_257093/bridge_E121_541533_N31_257093_park_sample_2.csv"
    ]

    param_dict = {
        '采样频率': 100,
        '桥梁全长': 1820,
        '桥梁EPSG代号': 32651,
    }

    # 最终结果
    res = measure_main.vehicle_analysis_module(param_dict, url_list, NN_df, CAE_df, bridge_type)
    print(res)


def format_local_url111(url_list):
    #转换成 本地服务器地址
    local_url = []
    for url in url_list:
        local_url.append(url_util.format_local_url_default(url))

    return local_url

def test_url():
    url_list = [
        "http://202.120.188.183:9093/api/uploads/files/csv/bridge_E121_541533_N31_257093/bridge_E121_541533_N31_257093_park_sample_1.csv",
        "http://202.120.188.183:9093/api/uploads/files/csv/bridge_E121_541533_N31_257093/bridge_E121_541533_N31_257093_park_sample_2.csv"
    ]

    local_url=url_util.format_local_url_list(url_list)

    print(local_url)

# 测试代码
if __name__ == '__main__':
    # testPredType1()
    # testPredType3()
    # testCaeType1()
    # testCaeType3()
    # testMesureType3()
    # testMesureType3_2()
    # testMesureType3_1()
    test_url()




